package com.wanjl.mq.listener;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author WanJl
 * @version 1.0
 * @title DirectListener
 * @description 监听并消费队列里的消息--定向
 * @create 2025/2/10
 */
@Slf4j
@Component
public class DirectListener {

    /**
     * 消费者监听并消费消息
     * 直接绑定队列和交换机的关系
     * @param message
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct.queue1"), //要绑定的队列
                    exchange = @Exchange(name = "mdxq.direct",type = ExchangeTypes.DIRECT), //要绑定的交换机
                    key = {"red","blue"}    //路由key  bindingKey  routeingKey
            )
    })
    public void listenQueueMessage01(String message) {
        log.info("消费者01监听并接收到direct.queue1队列中的消息，并且只监听key为red或blue的消息----->{}",message);
    }

    /**
     * 消费者监听并消费消息
     * 直接绑定队列和交换机的关系
     * @param message
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct.queue2"), //要绑定的队列
                    exchange = @Exchange(name = "mdxq.direct",type = ExchangeTypes.DIRECT), //要绑定的交换机
                    key = {"red","yellow"}    //路由key  bindingKey  routeingKey
            )
    })

    public void listenQueueMessage02(String message) {
        log.info("消费者02监听并接收到direct.queue2队列中的消息，并且只监听key为red或yellow的消息----->{}",message);
    }


    /**
     * 消费者监听并消费消息
     * 直接绑定队列和交换机的关系
     * @param message
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct.queue1"), //要绑定的队列
                    exchange = @Exchange(name = "mdxq.direct",type = ExchangeTypes.DIRECT), //要绑定的交换机
                    key = {"red","yellow"}    //路由key  bindingKey  routeingKey
            )
    })

    public void listenQueueMessage03(String message) {
        log.info("消费者03监听并接收到direct.queue1队列中的消息，并且只监听key为red或yellow的消息----->{}",message);
    }

    /**
     * 消费者监听并消费消息
     * 直接绑定队列和交换机的关系
     * @param message
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct.queue2"), //要绑定的队列
                    exchange = @Exchange(name = "mdxq.direct",type = ExchangeTypes.DIRECT), //要绑定的交换机
                    key = {"red","blue"}    //路由key  bindingKey  routeingKey
            )
    })
    public void listenQueueMessage04(String message) {
        log.info("消费者04监听并接收到direct.queue2队列中的消息，并且只监听key为red或blue的消息----->{}",message);
    }
}
